// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import  axios from 'axios'
import BaiduMap from 'vue-baidu-map';
import 'element-ui/lib/theme-chalk/index.css';
import timeUtils from '../static/timeUtils.js';
import coordtransform from 'coordtransform';
import vuedraggable from 'vuedraggable'; //拖动
import moment from 'moment'
import { config } from 'shelljs'
Vue.prototype.$moment = moment;//赋值使用
Vue.prototype.timeUtils=timeUtils;
Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.prototype.$axios = axios;
Vue.prototype.coordtransform = coordtransform
axios.defaults.baseURL = 'http://localhost:8002/'
// axios.defaults.baseURL = 'http://124.71.24.222:8002/'

Vue.use(BaiduMap, {
  // ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */
  ak: 'bDCokjX8Z3beOQv7qUmx0IBuBUxbG9Wr'
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>',
})
// axios.interceptors.request.use((config) => {
// 	config.headers.token = window.sessionStorage.getItem("token");
// 	return config;
// });
// 请求拦截  设置统一header
axios.interceptors.request.use(config => {
  if (localStorage.token){
    config.headers.token = localStorage.token;  //将token设置成请求头
  }      
  return config
}, error => {
  return Promise.reject(error)
})

//http响应拦截器
axios.interceptors.response.use(config=>{
 
  const code = config.data.code;
  if(code == "20011"){ //无权限 重新跳转
    window.location.href = '/'
  }
  return config
  
})